package kite.sso.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * 功能描述: <br>
 * 所属包名: kite.sso.config<br>
 * 创建人　: 白剑<br>
 * 创建时间: 2018/06/05 12:07:02<br>
 * 当前版本: 1.0<br>
 * 修改历史: <br>
 * 修改时间　　　　　修改人　　　　　版本变更　　　　　修改说明<br>
 * -----------------------------------------------------<br>
 * <br>
 */
@Configuration
public class DataSourceConfig {

    @Autowired
    private Environment env;

    @Bean
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name"));
        dataSource.setUrl(env.getProperty("spring.datasource.url"));
        dataSource.setUsername(env.getProperty("spring.datasource.username"));
        dataSource.setPassword(env.getProperty("spring.datasource.password"));
        dataSource.setMaxActive(env.getProperty("spring.datasource.druid.max-active", Integer.class));
        dataSource.setInitialSize(env.getProperty("spring.datasource.druid.initial-size", Integer.class));
        dataSource.setMaxWait(env.getProperty("spring.datasource.druid.max-wait", Integer.class));
        dataSource.setMinIdle(env.getProperty("spring.datasource.druid.min-idle", Integer.class));
        dataSource.setRemoveAbandoned(env.getProperty("spring.datasource.druid.remove-abandoned", Boolean.class));
        dataSource.setRemoveAbandonedTimeout(env.getProperty("spring.datasource.druid.remove-abandoned-timeout", Integer.class));
        dataSource.setConnectionProperties(env.getProperty("spring.datasource.druid.connection-properties"));
        dataSource.setTestWhileIdle(env.getProperty("spring.datasource.druid.test-while-idle", Boolean.class));
        return dataSource;
    }

}
